/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * FloorUI2.java
 *
 * Created on Aug 16, 2011, 7:38:23 PM
 */
package FloorUIForms;

import elevatormanagementsystem.Elevator;
import elevatormanagementsystem.LiftUIForms.LiftUI;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import javax.swing.border.Border;
import javax.swing.border.CompoundBorder;
import javax.swing.border.EmptyBorder;
import javax.swing.border.MatteBorder;
import javax.swing.*;


/**
 *
 * @author Danny
 */
public class FloorUI2 extends javax.swing.JPanel implements FloorUI {
    
    
    
    
    
    
// Inner class GuiTimerListener acting as timer
    private class GuiTimerListener implements ActionListener {

        public GuiTimerListener() {
        }

        @Override
        public void actionPerformed(ActionEvent e) {
            GuiTimerTick();
        }

        private void GuiTimerTick() {
      if (elevator.getDoorStatus().equals("open")) {
          if (elevator.getCurrentFloor() == 1) {
              //door image open
          }
          else if (elevator.getCurrentFloor() == 2) {
              //door image open              
          }
      }
      else if (elevator.getDoorStatus().equals("closed")) {
          //door 1 image closed
          //door 2 image closed
      }
      if (elevator.getCurrentFloor() == 1) {
          //first floor has border style
          //second floor has no border style
      }
      if (elevator.getCurrentFloor() == 2) {
          //second floor has border style
          //first floor has no border style
      }
    }
    }
    
    
    
    
    
    
    
    
    String namingConvention;
    Elevator elevator;
    LiftUI liftUI;

    ArrayList allCommands;
    ArrayList firstFloorCommands;
    ArrayList secondFloorCommands;
    
    Timer GuiUpdateTimer; 
    Timer elevatorChecker;

    /** Creates new form FloorUI2 */
    public FloorUI2(String floorNaming, Elevator e, LiftUI lui, int seconds) {
        initComponents();
        namingConvention = floorNaming;
            elevator = e;
            liftUI = lui;
            
            int GuiCounter = 500; //note this is ms 
            GuiUpdateTimer = new Timer(GuiCounter, new GuiTimerListener());
            GuiUpdateTimer.start();
            
            
            
//            >>> int delay = 100;//milliseconds
//>>> Timer time = new Time(delay, new TimerListener());
//>>>
//>>> class TimerListener implements ActionListener
//>>> {
//>>> public void actionPerformed(ActionEvent e)
//>>> {
//>>> runDesiredMethod();
//>>> }
//>>> }
//>>>
//>>> then all you need is
//>>>
//>>> time.start();
//>>>
//>>> and
//>>> time.stop();
            
            allCommands = new ArrayList();
            firstFloorCommands = new ArrayList();
            secondFloorCommands = new ArrayList(); 
            
//            // Sets the naming of floors to either US or UK
//            setFloorNaming();

            // Sets the current floor border
            borderCurrentFloorofElevator(elevator.getCurrentFloor());
    }
    
    private void addNewCommand(String command)
        {
            if (allCommands.contains(command))
            {
            }
            else
            {
                allCommands.add(command);
            }
        }

        private void addNewFirstFloorCommand(String command)
        {
            if (firstFloorCommands.contains(command))
            {
            }
            else
            {
                firstFloorCommands.add(command);
            }
        }
        private void addSecondFloorCommand(String command)
        {
            if (secondFloorCommands.contains(command))
            {
            }
            else
            {
                secondFloorCommands.add(command);
            }
        }
        private void removeCommand(String list, String command)
        {
            if (list.equals("allCommands"))
            {
                allCommands.remove(command);
            }
            else if (list.equals("firstFloorCommands"))
            {
                firstFloorCommands.remove(command);
            }
            else if (list.equals("secondFloorCommands"))
            {
                secondFloorCommands.remove(command);
            }
        }
        private String getNextCommand()
        {
            if (allCommands.size() != 0)
            {
                return allCommands.get(0).toString();
            }
            else
            {
                return "";
            }
        }

//        private void setFloorNaming()
//        {
//            if (namingConvention.equals("UK"))
//            {
//                firstFloorLbl.Text = "G";
//                secondFloorLbl.Text = "1";
//            }
//            else if (namingConvention.equals("US"))
//            {
//                firstFloorLbl.Text = "1";
//                secondFloorLbl.Text = "2";
//            }
//        }
 private void borderCurrentFloorofElevator(int floorNumber)
        {
            if (floorNumber == 1)
            {
                Border border = firstFloorPanel.getBorder();
                Border margin = new EmptyBorder(10,10,10,10);
                firstFloorPanel.setBorder(new CompoundBorder(border, margin));
            }
            else if (floorNumber == 2)
            {
                Border border = secondFloorPanel.getBorder();
                Border margin = new EmptyBorder(10,10,10,10);
                secondFloorPanel.setBorder(new CompoundBorder(border, margin));
            }
        }

        public void lightUpBttn(String floorNumber)
        {
            if (floorNumber.equals("firstup"))
            {
//               up bttn image upBttnFirst.Image = Properties.Resources.up_button_small_lit;
            }
            else if (floorNumber.equals("seconddown"))
            {
                // down button image downBttnSecond.Image = Properties.Resources.down_button_small_lit;
            }
            repaint();
        }
         public void lightOutBttn(String floorNumber)
        {
            if (floorNumber.equals("firstup"))
            {
                // up image upBttnFirst.Image = Properties.Resources.up_button_small;
            }
            else if (floorNumber.equals("seconddown"))
            {
                // down image downBttnSecond.Image = Properties.Resources.down_button_small;
            }
            repaint();
        }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        firstFloorPanel = new javax.swing.JPanel();
        upBttnFirst = new javax.swing.JButton();
        secondFloorPanel = new javax.swing.JPanel();
        downBttnSecond = new javax.swing.JButton();

        firstFloorPanel.setBorder(new javax.swing.border.MatteBorder(null));

        upBttnFirst.setText("Up");
        upBttnFirst.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                upBttnFirstActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout firstFloorPanelLayout = new javax.swing.GroupLayout(firstFloorPanel);
        firstFloorPanel.setLayout(firstFloorPanelLayout);
        firstFloorPanelLayout.setHorizontalGroup(
            firstFloorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, firstFloorPanelLayout.createSequentialGroup()
                .addContainerGap(172, Short.MAX_VALUE)
                .addComponent(upBttnFirst, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        firstFloorPanelLayout.setVerticalGroup(
            firstFloorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(firstFloorPanelLayout.createSequentialGroup()
                .addGap(42, 42, 42)
                .addComponent(upBttnFirst, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(62, Short.MAX_VALUE))
        );

        downBttnSecond.setText("Down");
        downBttnSecond.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                downBttnSecondActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout secondFloorPanelLayout = new javax.swing.GroupLayout(secondFloorPanel);
        secondFloorPanel.setLayout(secondFloorPanelLayout);
        secondFloorPanelLayout.setHorizontalGroup(
            secondFloorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, secondFloorPanelLayout.createSequentialGroup()
                .addContainerGap(172, Short.MAX_VALUE)
                .addComponent(downBttnSecond)
                .addContainerGap())
        );
        secondFloorPanelLayout.setVerticalGroup(
            secondFloorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(secondFloorPanelLayout.createSequentialGroup()
                .addGap(70, 70, 70)
                .addComponent(downBttnSecond, javax.swing.GroupLayout.DEFAULT_SIZE, 40, Short.MAX_VALUE)
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(secondFloorPanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(firstFloorPanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(30, Short.MAX_VALUE)
                .addComponent(secondFloorPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(firstFloorPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

private void upBttnFirstActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_upBttnFirstActionPerformed
//elevator.addNewCommand("upfirst");
            firstFloorCommands.add("up1");
            allCommands.add("up1"); 
            //Prob should make this update all at once on timer
            // image upBttnFirst.Image = Properties.Resources.up_button_small_lit;
            //new UCC.UCCPressUpButton(this, "firstup").Run(); 
}//GEN-LAST:event_upBttnFirstActionPerformed

private void downBttnSecondActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_downBttnSecondActionPerformed
    secondFloorCommands.add("down2");
    allCommands.add("down2");
    //change down button to lit
}//GEN-LAST:event_downBttnSecondActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton downBttnSecond;
    private javax.swing.JPanel firstFloorPanel;
    private javax.swing.JPanel secondFloorPanel;
    private javax.swing.JButton upBttnFirst;
    // End of variables declaration//GEN-END:variables

}
